﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MedicWeb.forms;
using MedicWeb.MedicService;

namespace MedicWeb.Service {
    public partial class SetTemplateActive : SessionPage {
        protected void Page_Load(object sender, EventArgs e) {
            string sid = Request.QueryString["id"];
            string type = Request.QueryString["type"];
            if (sid == null) {
                Response.StatusCode = 400;
                Response.StatusDescription = "Bad id";
            } else {
                int id = int.Parse(sid);
                Response.ContentType = "text/plain";
                Response.Write(""+id);
                try {
                    var mainService = new MainService();
                    mainService.SetTemplateActive(GetSession(), new PrintTemplate() {Id = id, Type = type});
                    Session["success"] = "Изменения сохранены успешно";
                }catch(Exception exception) {
                    Session["error"] = "Ошибка сохранения";
                }
            }
            Response.Flush();
            Response.End();
        }
    }
}